<?php
namespace Api\Controller;
use Think\Controller;
class AccountController extends Controller {

    /**
     * 查询帐号列表
     */
    public function user_list() {
        $offset = intval(I('get.offset'));
        $limit = intval(I('get.limit'));
        $order = strtoupper(I('get.order'));

        $sql = sprintf('SELECT * FROM account ORDER BY '
            .'id %s LIMIT %d OFFSET %d;', $order, $limit, $offset);

        $model = M();
        $accountCount = $model->query('SELECT COUNT(id) AS account_count FROM account;');
        $accountList = $model->query($sql);
        echo json_encode(array(
            'rows'  => $accountList,
            'total' => $accountCount[0]['account_count']
        ));
    }
}